##from xenocide import *
from actuator import *
import pyglet

class Decoration(object):
    def __init__(self,iParent,iPos):
        self.parent=iParent
        self.pos=[a for a in iPos]
        self.finished=False
    
    def step(self,dt):
        pass
    
    def draw(self):
        pass
        
class DamageText(Decoration):
    def __init__(self,iParent,iPos,iText):
        super(DamageText,self).__init__(iParent,iPos)
        self.text=iText
        pos=self.parent.getPosition(True)
        self.pos=[a+b for a,b in zip(pos,iPos)]
        self.color=[255,180,0,200]
        self.actuator=Actuator(0.,1.,1)
        self.label = pyglet.text.Label(iText,
                          font_name='Arial',
                          font_size=24,
                          x=0., y=0.,
                          anchor_x='center', anchor_y='center'
                          )

        
    def step(self,dt):
        
        #self.pos[0]=pos.x
        self.finished,dy=self.actuator.val()
        #self.label.x=self.pos[0]
        self.pos[1]+=dy*0.3
        self.color[2]=int(255*(1-dy))
        
        if self.finished:
            #can do this because weakly bound to parent
            delete(self)
        
    
    def draw(self):
        gl.glPushMatrix()
        gl.glTranslatef(self.pos[0],self.pos[1],0.0)
        #gl.glScalef(0.03,0.03,1.)
        self.label.draw()
        gl.glPopMatrix()
        
        